package cool.tenyears.admin.controller;

import cn.hutool.core.lang.tree.Tree;
import cool.tenyears.core.domain.R;
import cool.tenyears.service.MenuService;
import cool.tenyears.util.SaUtil;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LiChuan
 * @date 2021/7/12 12:46
 */
@RestController
@Api
@RequiredArgsConstructor
@Slf4j
public class AdminMenuController {
    private final MenuService menuService;

    @GetMapping("/role/detail")
    public R<?> menuByLogin() {
        Long userId = SaUtil.getUserId();
        log.info("当前用户ID：[[{}]]", userId);
        List<Tree<String>> trees = menuService.treeMenu(null);
        Map<String, List<Tree<String>>> map = new HashMap<>(3);
        map.put("checkedNodes", trees);
        return R.ok(map);
    }
}
